
################################################
# Media Influence and Spatial Voting: The Role of Perceived Party Positions
# Appendix
# Political Behavior
# Lucas Paulo da Silva
# RScript for appendices
# 28/02/2025
################################################


##### Set up ######

# R version 4.4.0 (2024-04-24 ucrt)

# load
library(haven)
library(estimatr)
library(dplyr)
library(ggplot2)
library(texreg)
library(ggtext)
library(plotrix)

require(rio)
require(foreign)
require(car)
require(plyr)
require(plm)
require(lme4)
library(multiwayvcov)
require(lmtest)
require(stargazer)
require(xtable)
require(psych)
require(grDevices)
require(plyr)
require(reshape2)
require(pBrackets)
require(MatchIt)
require(sandwich)

# clear environment
rm(list=ls())

# set working directory
setwd("C:/your/working/directory/")

# data
bsa_full <-read_dta("FB_BSA.DTA")
bsa_full <- bsa_full[bsa_full$North==1,] #remove non-northern observations
bsa_full <- bsa_full[!is.na(bsa_full$year),] #drop observations without a year

# reset working directory if you want a different folder for saved plots below
#setwd("C:/your/working/directory/")

# transform class variable
bsa_full$lmh_l <- as.factor(dplyr::recode(as.factor(bsa_full$lmh), 
                            "0" = 1,"1"=0,"2"=0))

# make liverpool, treatment, and constituency variables into factors
bsa_full$liverpool <- as.factor(bsa_full$liverpool) #run twice
bsa_full$treat <- as.factor(bsa_full$treat)
bsa_full$constituency97_id <- as.factor(bsa_full$constituency97_id)

# recode education as dummy variant
bsa_full$education_dum <- as.factor(case_when(bsa_full$education %in% 1 ~ 0,bsa_full$education %in% 2:6 ~ 1))

# separate by quasi-experiment
bsa <- bsa_full[bsa_full$year <= 1996,]
bsa_89_04 <- bsa_full[(bsa_full$treat == 1),]
bsa_89_04$treat <- as.factor(bsa_89_04$treat_endorse_Labour)





##### Appendix A - perceptions of party positions (robustness) ######

# limit to shared years
bsa_p <- bsa[!(bsa$year %in% c(1986, 1987)),]

# 1. no controls
ap1 <- lm_robust(labextr_p ~ liverpool*treat*lmh_l,
                 clusters = constituency97_id,
                 se_type = 'stata',
                 fixed_effects = ~constituency97_id + year,
                 data = bsa_p)
summary(ap1)$coefficients[,1:4]

# 2. controls recoded     
ap2 <- lm_robust(labextr_p ~ liverpool*treat*lmh_l + imp_age + female + education_dum + as.factor(religion_cat) + union + white,
                 clusters = constituency97_id,
                 se_type = 'stata',
                 fixed_effects = ~constituency97_id + year,
                 data = bsa_p)
summary(ap2)$coefficients[,1:4]

# 3. simple model, DV=Conservatives
ap3 <- lm_robust(conextr_p ~ liverpool*treat*lmh_l,
                 clusters = constituency97_id,
                 se_type = 'stata',
                 data = bsa_p)
summary(ap3)$coefficients[,1:4]

# 4. preferred model, DV=Conservatives
ap4 <- lm_robust(conextr_p ~ liverpool*treat*lmh_l + imp_age + female + as.factor(education) + as.factor(religion) + union + white + ownhome,
                 clusters = constituency97_id,
                 se_type = 'stata',
                 fixed_effects = ~constituency97_id + year,
                 data = bsa_p)
summary(ap4)$coefficients[,1:4]

# display
texreg(list(ap1,ap2,ap3,ap4),
       caption="DD/DDD for Perceived Party Positions (Robustness/Conservatives)",
       custom.model.names = c("1", "2", "3", "4"),
       custom.header = list("Labour" = 1:2, "Conservatives" = 3:4),
       custom.coef.map = list("liverpool1:treat1:lmh_l1" = "Merseyside*Treat*LWC (DDD)",
                              "liverpool1:treat1" = "Merseyside*Treat (DD)",
                              "liverpool1:lmh_l1" = "Merseyside*LWC", 
                              "treat1:lmh_l1" = "Treat*LWC"),
       include.ci = FALSE,
       no.margin = TRUE,
       caption.above = TRUE,
       booktabs = TRUE,
       siunitx = TRUE)





##### Appendix B - perceptions of party positions (with all years) ######

### all years

# 1. simple DD
ap1_all <- lm_robust(labextr_p ~ liverpool*treat,
                 clusters = constituency97_id,
                 se_type = 'stata',
                 data = bsa)
summary(ap1_all)$coefficients[,1:4]

# 2. preferred DD
ap2_all <- lm_robust(labextr_p ~ liverpool*treat + imp_age + female + as.factor(education) + as.factor(religion) + union + white + ownhome + as.factor(lmh),
                 clusters = constituency97_id,
                 se_type = 'stata',
                 fixed_effects = ~constituency97_id + year,
                 data = bsa)
summary(ap2_all)$coefficients[,1:4]

# 3. simple DDD
ap3_all <- lm_robust(labextr_p ~ liverpool*treat*lmh_l,
                 clusters = constituency97_id,
                 se_type = 'stata',
                 data = bsa)
summary(ap3_all)$coefficients[,1:4]

# 4. preferred DDD
ap4_all <- lm_robust(labextr_p ~ liverpool*treat*lmh_l + imp_age + female + as.factor(education) + as.factor(religion) + union + white + ownhome,
                 clusters = constituency97_id,
                 se_type = 'stata',
                 fixed_effects = ~constituency97_id + year,
                 data = bsa)
summary(ap4_all)$coefficients[,1:4]

# display
texreg(list(ap1_all,ap2_all,ap3_all,ap4_all),
       caption="DD/DDD for Perceived Party Positions (with All Years)",
       custom.model.names = c("1", "2", "3", "4"),
       custom.header = list("DD" = 1:2, "DDD" = 3:4),
       custom.coef.map = list("liverpool1:treat1:lmh_l1" = "Merseyside*Treat*LWC (DDD)",
                              "liverpool1:treat1" = "Merseyside*Treat (DD)",
                              "liverpool1:lmh_l1" = "Merseyside*LWC", 
                              "treat1:lmh_l1" = "Treat*LWC"),
       include.ci = FALSE,
       no.margin = TRUE,
       caption.above = TRUE,
       booktabs = TRUE,
       siunitx = TRUE)





##### Appendix C - ideological positions (robustness) ######

# limit to shared years
bsa_i <- bsa[!(bsa$year %in% c(1986, 1989)),]

# 1. No controls
ai1 <- lm_robust(unions_lr ~ liverpool*treat*lmh_l,
                 clusters = constituency97_id,
                 se_type = 'stata',
                 fixed_effects = ~constituency97_id + year,
                 data = bsa_i)
summary(ai1)$coefficients[,1:4]

# 2. Controls recoded    
ai2 <- lm_robust(unions_lr ~ liverpool*treat*lmh_l + imp_age + female + education_dum + as.factor(religion_cat) + union + white,
                 clusters = constituency97_id,
                 se_type = 'stata',
                 fixed_effects = ~constituency97_id + year,
                 data = bsa_i)
summary(ai2)$coefficients[,1:4]

# 3. Simple Model, DV=unions_lr scale    
ai3 <- lm_robust(unions_lr_sc ~ liverpool*treat*lmh_l,
                 clusters = constituency97_id,
                 se_type = 'stata',
                 data = bsa_i)
summary(ai3)$coefficients[,1:4]

# 4. Preferred Model, DV=unions_lr scale    
ai4 <- lm_robust(unions_lr_sc ~ liverpool*treat*lmh_l + imp_age + female + as.factor(education) + as.factor(religion) + union + white + ownhome,
                 clusters = constituency97_id,
                 se_type = 'stata',
                 fixed_effects = ~constituency97_id + year,
                 data = bsa_i)
summary(ai4)$coefficients[,1:4]

# display
texreg(list(ai1,ai2,ai3,ai4),
       caption="DD/DDD for Ideological Positions (Robustness)",
       custom.model.names = c("1", "2", "3", "4"),
       custom.header = list("Dummy" = 1:2, "Scale" = 3:4),
       custom.coef.map = list("liverpool1:treat1:lmh_l1" = "Merseyside*Treat*LWC (DDD)",
                              "liverpool1:treat1" = "Merseyside*Treat (DD)",
                              "liverpool1:lmh_l1" = "Merseyside*LWC", 
                              "treat1:lmh_l1" = "Treat*LWC"),
       include.ci = FALSE,
       no.margin = TRUE,
       caption.above = TRUE,
       booktabs = TRUE,
       siunitx = TRUE)





##### Appendix D - ideological positions (additional measures) ######

bsa_i_add <- bsa[!(bsa$year %in% 1986),]

# calculate percentage in 1989 before treatment
bsa1989 <- bsa[bsa$year %in% 1989,]
bsa1989_tab <- table(bsa1989$treat[!is.na(bsa1989$redist_lr)])
bsa1989_tab[1] / sum(bsa1989_tab) * 100



### redistribution

# 1. Simple model, DV=redist_lr   
ai1_add <- lm_robust(redist_lr ~ liverpool*treat*lmh_l,
                     clusters = constituency97_id,
                     se_type = 'stata',
                     data = bsa_i_add)
summary(ai1_add)$coefficients[,1:4]

# 2. Preferred Model, DV=redist_lr   
ai2_add <- lm_robust(redist_lr ~ liverpool*treat*lmh_l + imp_age + female + as.factor(education) + as.factor(religion) + union + white + ownhome,
                     clusters = constituency97_id,
                     se_type = 'stata',
                     fixed_effects = ~constituency97_id + year,
                     data = bsa_i_add)
summary(ai2_add)$coefficients[,1:4]

# 3. Simple model, DV=voteleave2   
ai3_add <- lm_robust(voteleave2 ~ liverpool*treat*lmh_l,
                 clusters = constituency97_id,
                 se_type = 'stata',
                 data = bsa)
summary(ai3_add)$coefficients[,1:4]

# 4. Preferred Model, DV=voteleave2  
ai4_add <- lm_robust(voteleave2 ~ liverpool*treat*lmh_l + imp_age + female + as.factor(education) + as.factor(religion) + union + white + ownhome,
                 clusters = constituency97_id,
                 se_type = 'stata',
                 fixed_effects = ~constituency97_id + year,
                 data = bsa)
summary(ai4_add)$coefficients[,1:4]

# display
texreg(list(ai1_add,ai2_add,ai3_add,ai4_add),
       caption="DD/DDD for Ideological Positions (Additional)",
       custom.model.names = c("1", "2", "3", "4"),
       custom.header = list("Dummy" = 1:2, "Scale" = 3:4),
       custom.coef.map = list("liverpool1:treat1:lmh_l1" = "Merseyside*Treat*LWC (DDD)",
                              "liverpool1:treat1" = "Merseyside*Treat (DD)",
                              "liverpool1:lmh_l1" = "Merseyside*LWC", 
                              "treat1:lmh_l1" = "Treat*LWC"),
       include.ci = FALSE,
       no.margin = TRUE,
       caption.above = TRUE,
       booktabs = TRUE,
       siunitx = TRUE)





##### Appendix E - party support ######

# 1. no controls
av1 <- lm_robust(labour ~ liverpool*treat*lmh_l,
                 clusters = constituency97_id,
                 se_type = 'stata',
                 fixed_effects = ~constituency97_id + year,
                 data = bsa)
summary(av1)$coefficients[,1:4]

# 2. controls recoded  
av2 <- lm_robust(labour ~ liverpool*treat*lmh_l + imp_age + female + education_dum + as.factor(religion_cat) + union + white,
                 clusters = constituency97_id,
                 se_type = 'stata',
                 fixed_effects = ~constituency97_id + year,
                 data = bsa)
summary(av2)$coefficients[,1:4]

# 3. simple model, DV=Conservatives
av3 <- lm_robust(conservative ~ liverpool*treat*lmh_l,
                 clusters = constituency97_id,
                 se_type = 'stata',
                 data = bsa)
summary(av3)$coefficients[,1:4]

# 4. preferred model, DV=Conservatives
av4 <- lm_robust(conservative ~ liverpool*treat*lmh_l + imp_age + female + as.factor(education) + as.factor(religion) + union + white + ownhome,
                    clusters = constituency97_id,
                    se_type = 'stata',
                    fixed_effects = ~constituency97_id + year,
                    data = bsa)
summary(av4)$coefficients[,1:4]

# display
texreg(list(av1,av2,av3,av4),
       caption="DD/DDD for Party Support (Robustness/Conservatives)",
       custom.model.names = c("1", "2", "3", "4"),
       custom.header = list("Labour" = 1:2, "Conservative" = 3:4),
       custom.coef.map = list("liverpool1:treat1:lmh_l1" = "Merseyside*Treat*LWC (DDD)",
                "liverpool1:treat1" = "Merseyside*Treat (DD)",
                "liverpool1:lmh_l1" = "Merseyside*LWC", 
                "treat1:lmh_l1" = "Treat*LWC"),
       include.ci = FALSE,
       no.margin = TRUE,
       caption.above = TRUE,
       booktabs = TRUE,
       siunitx = TRUE)





##### Appendix F - The Sun's endorsement of the Labour Party #####

# limit to shared years
bsa_i_04 <- bsa_89_04[!(bsa_89_04$year %in% 1989),]

### ideological positions

# 1. simple DD
ai1_04 <- lm_robust(unions_lr ~ liverpool*treat,
                clusters = constituency97_id,
                se_type = 'stata',
                data = bsa_i_04)
summary(ai1_04)$coefficients[,1:4]

# 2. preferred DD
ai2_04 <- lm_robust(unions_lr ~ liverpool*treat + imp_age + female + as.factor(education) + as.factor(religion) + union + white + ownhome + as.factor(lmh),
                clusters = constituency97_id,
                se_type = 'stata',
                fixed_effects = ~constituency97_id + year,
                data = bsa_i_04)
summary(ai2_04)$coefficients[,1:4]

# 3. simple DDD
ai3_04 <- lm_robust(unions_lr ~ liverpool*treat*lmh_l,
                clusters = constituency97_id,
                se_type = 'stata',
                data = bsa_i_04)
summary(ai3_04)$coefficients[,1:4]

# 4. preferred DDD
ai4_04 <- lm_robust(unions_lr ~ liverpool*treat*lmh_l + imp_age + female + as.factor(education) + as.factor(religion) + union + white + ownhome,
                clusters = constituency97_id,
                se_type = 'stata',
                fixed_effects = ~constituency97_id + year,
                data = bsa_i_04)
summary(ai4_04)$coefficients[,1:4]

# display
texreg(list(ai1_04,ai2_04,ai3_04,ai4_04),
       caption="DD/DDD for Ideological Positions (Sun Endorsing Labour)",
       custom.model.names = c("1", "2", "3", "4"),
       custom.header = list("DD" = 1:2, "DDD" = 3:4),
       custom.coef.map = list("liverpool1:treat1:lmh_l1" = "Merseyside*Treat*LWC (DDD)",
                              "liverpool1:treat1" = "Merseyside*Treat (DD)",
                              "liverpool1:lmh_l1" = "Merseyside*LWC", 
                              "treat1:lmh_l1" = "Treat*LWC"),
       include.ci = FALSE,
       no.margin = TRUE,
       caption.above = TRUE,
       booktabs = TRUE,
       siunitx = TRUE)



### party support

# 1. simple DD
av1_04 <- lm_robust(labour ~ liverpool*treat,
                clusters = constituency97_id,
                se_type = 'stata',
                data = bsa_89_04)
summary(av1_04)$coefficients[,1:4]

# 2. preferred DD
av2_04 <- lm_robust(labour ~ liverpool*treat + imp_age + female + as.factor(education) + as.factor(religion) + union + white + ownhome + as.factor(lmh),
                clusters = constituency97_id,
                se_type = 'stata',
                fixed_effects = ~constituency97_id + year,
                data = bsa_89_04)
summary(av2_04)$coefficients[,1:4]

# 3. simple DDD
av3_04 <- lm_robust(labour ~ liverpool*treat*lmh_l,
                clusters = constituency97_id,
                se_type = 'stata',
                data = bsa_89_04)
summary(av3_04)$coefficients[,1:4]

# 4. preferred DDD
av4_04 <- lm_robust(labour ~ liverpool*treat*lmh_l + imp_age + female + as.factor(education) + as.factor(religion) + union + white + ownhome,
                clusters = constituency97_id,
                se_type = 'stata',
                fixed_effects = ~constituency97_id + year,
                data = bsa_89_04)
summary(av4_04)$coefficients[,1:4]

# display
texreg(list(av1_04,av2_04,av3_04,av4_04),
       caption="DD/DDD for Party Support (Sun Endorsing Labour)",
       custom.model.names = c("1", "2", "3", "4"),
       custom.header = list("DD" = 1:2, "DDD" = 3:4),
       custom.coef.map = list("liverpool1:treat1:lmh_l1" = "Merseyside*Treat*LWC (DDD)",
                              "liverpool1:treat1" = "Merseyside*Treat (DD)",
                              "liverpool1:lmh_l1" = "Merseyside*LWC", 
                              "treat1:lmh_l1" = "Treat*LWC"),
       include.ci = FALSE,
       no.margin = TRUE,
       caption.above = TRUE,
       booktabs = TRUE,
       siunitx = TRUE)



### ideological positions (1983-2004)

# limit to shared years
bsa_i_full <- bsa_full[!(bsa_full$year %in% c(1986, 1989)),]

# 1. simple DD
ai1_83_04 <- lm_robust(unions_lr ~ liverpool*treat,
                    clusters = constituency97_id,
                    se_type = 'stata',
                    data = bsa_i_full)
summary(ai1_83_04)$coefficients[,1:4]

# 2. preferred DD
ai2_83_04 <- lm_robust(unions_lr ~ liverpool*treat + imp_age + female + as.factor(education) + as.factor(religion) + union + white + ownhome + as.factor(lmh),
                    clusters = constituency97_id,
                    se_type = 'stata',
                    fixed_effects = ~constituency97_id + year,
                    data = bsa_i_full)
summary(ai2_83_04)$coefficients[,1:4]

# 3. simple DDD
ai3_83_04 <- lm_robust(unions_lr ~ liverpool*treat*lmh_l,
                    clusters = constituency97_id,
                    se_type = 'stata',
                    data = bsa_i_full)
summary(ai3_83_04)$coefficients[,1:4]

# 4. preferred DDD
ai4_83_04 <- lm_robust(unions_lr ~ liverpool*treat*lmh_l + imp_age + female + as.factor(education) + as.factor(religion) + union + white + ownhome,
                    clusters = constituency97_id,
                    se_type = 'stata',
                    fixed_effects = ~constituency97_id + year,
                    data = bsa_i_full)
summary(ai4_83_04)$coefficients[,1:4]

# display
texreg(list(ai1_83_04,ai2_83_04,ai3_83_04,ai4_83_04),
       caption="DD and DDD for Ideological Positions (1983-2004)",
       custom.model.names = c("1", "2", "3", "4"),
       custom.header = list("DD" = 1:2, "DDD" = 3:4),
       custom.coef.map = list("liverpool1:treat1:lmh_l1" = "Merseyside*Treat*LWC (DDD)",
                              "liverpool1:treat1" = "Merseyside*Treat (DD)",
                              "liverpool1:lmh_l1" = "Merseyside*LWC", 
                              "treat1:lmh_l1" = "Treat*LWC"),
       include.ci = FALSE,
       no.margin = TRUE,
       caption.above = TRUE,
       booktabs = TRUE,
       siunitx = TRUE)





##### Appendix G - trends visualized ######

# create functions 
data_summary <- function(data, varname, groupnames){
  require(plyr)
  require(plotrix)
  summary_func <- function(x, col){
    c(mean = mean(x[[col]], na.rm=TRUE),
      sd = sd(x[[col]], na.rm=TRUE),
      se = std.error(x[[col]], na.rm=TRUE))
  }
  data_sum<-ddply(data, groupnames, .fun=summary_func,
                  varname)
  data_sum <- rename(data_sum, c("mean" = varname))
  return(data_sum)
}

number_ticks <- function(n) {function(limits) pretty(limits, n)}



### perceptions of party positioning

# make year every two years due to small amounts of group data per year
bsa$year_2 <- dplyr::recode(as.factor(bsa$year), 
    "1983" = 1983.5, "1984" = 1983.5, "1985" = 1985.5, "1986" = 1985.5, "1987" = 1987.5, 
    "1988" = 1987.5, "1989" = 1989.5, "1990" = 1989.5, "1991" = 1991.5, "1992" = 1991.5, 
    "1993" = 1993.5, "1994" = 1993.5, "1995" = 1995.5, "1996" = 1995.5)
bsa$year_2[bsa$treat==0 & bsa$year == 1989] <- 1987.5

# create labour extreme trend dataframe 
trend_df_labextr <- data_summary(bsa[!(bsa$lmh_l=="NA" | bsa$labextr_p=="NA"),], varname="labextr_p", 
                                 groupnames=c("liverpool", "year_2", "lmh_l"))

# create labour extreme line plot
ggplot(trend_df_labextr, aes(x=year_2, y=labextr_p, group=interaction(liverpool,lmh_l), color=interaction(liverpool,lmh_l))) +
  geom_line(size=1.2) + 
  geom_point(size=3.5) + 
  scale_color_manual(values = c("0.0"="#74c476", "1.0"="#6baed6", "0.1"="#006d2c", "1.1"="#08519c"),
                     breaks = c("1.1","1.0","0.1","0.0"),
                     labels = c("MS*LWC","MS*MHC","NE*LWC","NE*MHC")) +
  scale_x_continuous(limits = c(1983, 1996),breaks=number_ticks(7)) +
  scale_y_continuous(limits = c(0, 1),breaks=number_ticks(5)) +
  geom_vline(xintercept = 1989.29,linetype="dashed") +
  geom_richtext(aes(x = 1989.29, y = 1, label = "*Sun* Boycott"),label.color = NA,color="black", size = 6) +
  labs(x="Year",
       y="Proportion that Perceive Labour as Extreme",
       color="Key") +
  theme(
    axis.title.y = element_text(size = 19),
    axis.text.y = element_text(size = 17),
    axis.title.x = element_text(size = 19),
    axis.text.x = element_text(size = 17, vjust=0.7),
    legend.title = element_text(size = 19), 
    legend.text = element_text(size = 15))

# save
ggsave("timeline_ppp.png", plot = last_plot(), dpi = 300, width = 10, height = 6)



### ideological position 

# make year every two years due to small amounts of group data per year
bsa_full$year_2 <- dplyr::recode(as.factor(bsa_full$year), "1983" = 1983.5,
                                 "1984" = 1983.5, "1985" = 1985.5, "1986" = 1985.5,
                                 "1987" = 1987.5, "1988" = 1987.5, "1989" = 1989.5,
                                 "1990" = 1989.5, "1991" = 1991.5, "1992" = 1991.5,
                                 "1993" = 1993.5, "1994" = 1993.5, "1995" = 1995.5,
                                 "1996" = 1995.5, "1997" = 1997.5, "1998" = 1997.5, 
                                 "1999" = 1999.5, "2000" = 1999.5, "2001" = 2001.5, 
                                 "2002" = 2001.5, "2003" = 2003.5, "2004" = 2003.5,)
bsa_full$year_2[bsa_full$treat_endorse_Labour==0 & bsa_full$year == 1997] <- 1995.5

# create conservative trend dataframe (no class) and remove one NaN row
trend_df_union <- data_summary(bsa_full[!bsa_full$lmh_l=="NA",], varname="unions_lr", 
                               groupnames=c("liverpool", "year_2", "lmh_l"))

# create conservative line plot
ggplot(trend_df_union, aes(x=year_2, y=unions_lr, group=interaction(liverpool,lmh_l), color=interaction(liverpool,lmh_l))) +
  geom_line(size=1.2) + 
  geom_point(size=3.5) + 
  scale_color_manual(values = c("0.0"="#74c476", "1.0"="#6baed6", "0.1"="#006d2c", "1.1"="#08519c"),
                     breaks = c("1.1","1.0","0.1","0.0"),
                     labels = c("MS*LWC","MS*MHC","NE*LWC","NE*MHC")) +
  scale_x_continuous(limits = c(1983, 1999),breaks=number_ticks(7)) +
  scale_y_continuous(limits = c(0, 1),breaks=number_ticks(5)) +
  geom_vline(xintercept = 1989.29,linetype="dashed") +
  geom_richtext(aes(x = 1989.29, y = 1, label = "*Sun* Boycott"),label.color = NA,color="black", size = 6) +
  geom_vline(xintercept = 1997.21,linetype="dashed") +
  geom_richtext(aes(x = 1997.21, y = 1, label = "Endorses Labour"),label.color = NA,color="black", size = 6) +
  labs(x="Year",
       y="Proportion that Think Unions are Too Powerful",
       color="Key") +
  theme(
    axis.title.y = element_text(size = 19),
    axis.text.y = element_text(size = 17),
    axis.title.x = element_text(size = 19),
    axis.text.x = element_text(size = 17, vjust=0.7),
    legend.title = element_text(size = 19), 
    legend.text = element_text(size = 15))

ggsave("timeline_ideology.png", plot = last_plot(), dpi = 300, width = 10, height = 6)



### party support

# create labour trend dataframe (no class) and remove one NaN row
trend_df_labsup <- data_summary(bsa_full[!bsa_full$lmh_l=="NA",], varname="labour", 
                                groupnames=c("liverpool", "year_2", "lmh_l"))

# create labour line plot
ggplot(trend_df_labsup, aes(x=year_2, y=labour, group=interaction(liverpool,lmh_l), color=interaction(liverpool,lmh_l))) +
  geom_line(size=1.2) + 
  geom_point(size=3.5) + 
  scale_color_manual(values = c("0.0"="#74c476", "1.0"="#6baed6", "0.1"="#006d2c", "1.1"="#08519c"),
                     breaks = c("1.1","1.0","0.1","0.0"),
                     labels = c("MS*LWC","MS*MHC","NE*LWC","NE*MHC")) +
  scale_x_continuous(limits = c(1982, 2005),breaks=number_ticks(6)) +
  scale_y_continuous(limits = c(0, 1),breaks=number_ticks(5)) +
  geom_vline(xintercept = 1989.29,linetype="dashed") +
  geom_richtext(aes(x = 1989.29, y = 1, label = "*Sun* Boycott"),label.color = NA,color="black", size = 6) +
  geom_vline(xintercept = 1997.21,linetype="dashed") +
  geom_richtext(aes(x = 1997.21, y = 1, label = "Endorses Labour"),label.color = NA,color="black", size = 6) +
  labs(x="Year",
       y="Proportion that Support Labour",
       color="Key") +
  theme(
    axis.title.y = element_text(size = 19),
    axis.text.y = element_text(size = 17),
    axis.title.x = element_text(size = 19),
    axis.text.x = element_text(size = 17, vjust=0.7),
    legend.title = element_text(size = 19), 
    legend.text = element_text(size = 15))

ggsave("timeline_support.png", plot = last_plot(), dpi = 300, width = 10, height = 6)



